package com.cf.r1020;

import java.io.*;

public class b {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        in.nextToken(); int T = (int) in.nval;
        while (T-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        in.nextToken(); int n = (int) in.nval;
        in.nextToken(); int x = (int) in.nval;
        if (n == 1) {
            out.println(0);
            return;
        }
        int[] ans = new int[n];
        if (x >= n) {
            for (int i = 0; i < n; i++) {
                ans[i] = i;
            }
        } else {
            for (int i = 0; i < n - 1; i++) {
                if (i < x) ans[i] = i;
                else ans[i] = i + 1;
            }
            ans[n - 1] = x;
        }
        for (int a : ans) {
            out.print(a + " ");
        }
        out.println();
    }
}
